/**
 * 订单管理 交易订单
 */
<template>
  <div>
    <!-- 面包屑导航 -->
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>交易订单</el-breadcrumb-item>
    </el-breadcrumb>
    <!-- 搜索筛选 -->
    <el-form :inline="true" :model="formInline" class="user-search">

      <el-form-item label="搜索：">
        <el-input size="small" v-model="orderNumber" placeholder="输入订单号"></el-input>
      </el-form-item>
      <!-- <el-form-item>
        <el-select size="small" v-model="status" placeholder="请选择">
          <el-option v-for="type in payType" :label="type.key" :value="type.value" :key="type.value"></el-option>
        </el-select>
      </el-form-item> -->

      <el-form-item>
        <el-button size="small" type="primary" icon="el-icon-search" @click="getOrderList(1)">搜索</el-button>
      </el-form-item>


      <download-excel
          class = "export-excel-wrapper"
          :data = "fileList"
          :fields = "fieldsList"
          name = "订单列表.xls">
          <!-- 上面可以自定义自己的样式，还可以引用其他组件button -->
          <el-button type="primary" size="small">导出EXCEL</el-button>
      </download-excel>



    </el-form>
    <!--列表-->
    <el-table size="small" :data="listData" highlight-current-row v-loading="loading" border element-loading-text="拼命加载中"
      style="width: 100%;">

      
      <el-table-column sortable prop="orderNumber" label="订单号" width="210" show-overflow-tooltip>
      </el-table-column>

      <el-table-column prop="id" label="用户手机号" width="100">
        <template slot-scope="scope">
          <div >{{scope.row.userEntity.mobile}}</div>

        </template>
      </el-table-column>
      <el-table-column prop="integral" label="消耗积分" width="100">
      </el-table-column>



      <el-table-column prop="addTime" label="商品图" width="100">
        <template slot-scope="scope">
          <el-image style="width: 80px; height: 80px;border-radius: 10px;"
            :src="scope.row.orderCommodity.main_img"></el-image>
        </template>
      </el-table-column>
      <el-table-column sortable label="商品名称"   width="300" show-overflow-tooltip>
        <template slot-scope="scope">
          <div>{{ scope.row.orderCommodity.commodity_title }}</div>
        </template>
      </el-table-column>
      
      <el-table-column sortable prop="status" label="订单状态" width="120" show-overflow-tooltip>
        <template slot-scope="scope">
          <div v-if="scope.row.status == 1">待核销</div>
          <div v-if="scope.row.status == 2">待核销</div>
          <div v-if="scope.row.status == 3">已核销</div>
        </template>

      </el-table-column>
      <el-table-column prop="id" label="核销店铺" width="100">
        <template slot-scope="scope">
          <div v-if="scope.row.stationEntity">{{ scope.row.stationEntity.station_name }}</div>
        </template>

      </el-table-column>
      <el-table-column sortable prop="createTime" label="核销时间" width="180" show-overflow-tooltip>
        <template slot-scope="scope">
          <div v-if="scope.row.delivery_time">{{ transformDate(scope.row.delivery_time) }}</div>
        </template>
      </el-table-column>
      <el-table-column sortable prop="createTime" label="创建时间" width="180" show-overflow-tooltip>
        <template slot-scope="scope">
          <div>{{ transformDate(scope.row.creation_time) }}</div>
        </template>
      </el-table-column>

    </el-table>
    <!-- 分页组件 -->
    <Pagination v-bind:child-msg="pageparm" @callFather="callFather"></Pagination>

  </div>
</template>

<script>
import { queryIntegralOrder, getOrderDetails, setOrderRefund, getClassifyList } from '../../api/userMG'
import Pagination from '../../components/Pagination'
export default {
  data() {
    return {
      loading: false, //是显示加载
      editFormVisible: false, //控制编辑页面显示与隐藏
      fileList:[],
      listData: [], //用户数据
      // 分页参数
      pageparm: {
        currentPage: 1,
        pageSize: 20,
        total: 10
      },

      orderNumber:"",

      
       // 导出Excel 字段
       fieldsList: {
        "订单号": "orderNumber",    //常规字段
        "手机号":"mobile",
        "消耗积分":"integral",
        "商品名称":"commodity_title",
        "订单状态":"status",
        "消耗积分":"integral",
        "核销店铺":"station_name",
        "核销时间":"delivery_time",
        "创建时间":"creation_time"

      },




    }
  },
  // 注册组件
  components: {
    Pagination
  },
  /**
   * 数据发生改变
   */

  /**
   * 创建完毕
   */
  created() {

    this.getOrderList(1)


  },

  /**
   * 里面的方法只有被调用才会执行
   */
  methods: {
    
    // 获取订单列表
    getOrderList(page) {
      this.loading = true;
      var parameter = {
        key: this.orderNumber,
        page: (page - 1) * 20,
      };
      queryIntegralOrder(parameter).then((res) => {
        this.loading = false;
        if (res.code == 200) {
          this.listData = res.data.orderBasic
    

          console.log('res.data.list', this.listData)


          var fileList = []

          for (let index = 0; index <  this.listData.length; index++) {
            const element =  this.listData[index];

            var statusName = "";

            if (element.status == 1) {
              statusName =  "待核销"
            }
            if (element.status == 2) {
              statusName =  "待核销"
            }
            if (element.status == 3) {
              statusName =  "已核销"
            }


            var station_name = "";
            if (element.stationEntity) {
              station_name = element.stationEntity.station_name
            }

            var delivery_time = "";
            if (element.stationEntity) {
              delivery_time = this.transformDate(element.delivery_time) 
            }

            var creation_time = this.transformDate(element.creation_time) ;
    


            var item = {
              orderNumber:element.orderNumber,//订单号
              mobile:element.userEntity.mobile,//用户手机号
              integral:element.integral,//消耗积分
              commodity_title:element.orderCommodity.commodity_title,//商品名称
              status:statusName,//订单状态
              station_name:station_name ,//核销店铺
              delivery_time:delivery_time,//核销时间
              creation_time:creation_time,//下单时间

            }
            

            fileList.push(item)



          }

          this.fileList = fileList;










          this.pageparm.currentPage = page
          this.pageparm.total = res.data.count
 
          return;
        }
        this.$message({
          type: "info",
          message: res.msg,
        });
      });
    },
    
    // 分页插件事件
    callFather(parm) {
      // this.formInline.page = parm.currentPage
      // this.formInline.limit = parm.pageSize
      this.getOrderList(parm.currentPage)
    },
    // 搜索事件
    search() {
      this.getOrderList(1)
    },
    //显示编辑界面
    handleEdit: function (index, row) {
      this.editFormVisible = true
      this.orderInfo = row;
      this.getOrderDetails()
    },

   
  }
}
</script>

<style scoped>
.user-search {
  margin-top: 20px;
}

.userRole {
  width: 100%;
}
</style>

 
 

 